package com.lack.project.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lack.openApicommon.model.entity.InterfaceInfo;
import com.lack.project.common.ErrorCode;
import com.lack.project.exception.BusinessException;
import com.lack.project.mapper.InterfaceInfoMapper;
import com.lack.project.service.InterfaceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author qings
 * @description 针对表【interface_info(openApi.`interface_info`)】的数据库操作Service实现
 * @createDate 2024-08-20 15:16:36
 */
@Service
public class InterfaceInfoServiceImpl extends ServiceImpl<InterfaceInfoMapper, InterfaceInfo>
        implements InterfaceInfoService {

    @Override
    public void validInterfaceInfo(InterfaceInfo interfaceInfo, boolean add) {
        // 获取接口名称
        String name = interfaceInfo.getName();
        // 获取接口描述信息
        String description = interfaceInfo.getDescription();
        // 获取接口的请求URL
        String url = interfaceInfo.getUrl();
        // 获取接口的请求头信息
        String requestHeader = interfaceInfo.getRequestHeader();
        // 获取接口的响应头信息
        String responseHeader = interfaceInfo.getResponseHeader();
        // 获取接口的状态信息
        Integer status = interfaceInfo.getStatus();
        // 获取接口的请求方法（如GET、POST等）
        String method = interfaceInfo.getMethod();
        // 获取接口所属用户的标识符
        Long userId = interfaceInfo.getUserId();


        if (interfaceInfo == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }
        // 创建时，所有参数必须非空
        if (add) {
            if (StringUtils.isAnyBlank(name, description, url, requestHeader, responseHeader,method)) {
                throw new BusinessException(ErrorCode.PARAMS_ERROR);
            }
        }
        if (StringUtils.isNotBlank(name) && name.length() > 50) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "名称过长");
        }
        if (StringUtils.isNotBlank(description)&& description.length() > 100){
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "描述过长");
        }

    }

}




